/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* MpmProjectCustomerService
* 项目客户信息
*
* 修改纪录
* 2021-11-10 版本：1.0 chengengwei 创建。
* @version 版本：1.0
* @author 作者：chengengwei
* 创建日期：2021-11-10
*/
package com.topscomm.mpm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.mpm.pojo.MpmProjectCustomerEntity;
import com.topscomm.mpm.pojo.MpmProjectEntity;
import com.topscomm.pub.util.StringBufferProxy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.mpm.service.IMpmProjectCustomerService;
import com.topscomm.mpm.service.impl.auto.MpmProjectCustomerServiceAuto;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service(value = "mpmProjectCustomerService")
@Scope(value = "singleton")
public class MpmProjectCustomerService extends MpmProjectCustomerServiceAuto implements IMpmProjectCustomerService {

    /**
     * @author: chengengwei
     * @date: 2021-11-10
     * @description: 删除并添加客户信息
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeAndAddRecord(List<Map> customerList) {
        if (customerList == null || customerList.size() == 0) {
            return;
        }
        StringBufferProxy whereSql = new StringBufferProxy();
        whereSql.appendSingle(" sourcetype = '{0}' and sourceid = {1} ", customerList.get(0).get("sourcetype"),
                customerList.get(0).get("sourceid"));
        this.deleteByWhere(whereSql.toString());
        List<BasicEntity> insertBatchList = new ArrayList<>();
        for (Map map : customerList) {
            MpmProjectCustomerEntity customerEntity = new MpmProjectCustomerEntity();
            customerEntity.convertFromMap(map);
            insertBatchList.add(customerEntity);
        }
        this.insertBatch(insertBatchList);
    }
}
